package chapter12.casePage

/**
  * @Copyright: Shanghai Definesys Company.All rights reserved.
  * @Description:
  * @author: chuhaitao
  * @since: 2019/1/20 21:29
  * @history:
  *          1.2019/1/20 created by chuhaitao
  */
object CaseClassDemo03 {
  def main(args: Array[String]): Unit = {
    var bundle = Bundle("资治通鉴", 10.00, Book("西游记", 100), Book("西游记", 100))

    println(test1(bundle))

  }


  def test1(item: Item):Double={

    item match {
      case Book(_,price)=>price
      case Bundle(_,discount, rest @_*)=> rest.map(test1).sum-discount
     }

  }
}


abstract class Item

case class Book(desc: String, price: Double) extends Item

case class Bundle(desc: String, discount: Double, item: Item*) extends Item